package com.example.SpringBoot_demo.controller;

import com.example.SpringBoot_demo.bean.User;
import com.example.SpringBoot_demo.service.ITreeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
public class TreeController {

    @Autowired
    private ITreeService treeService;

    @GetMapping("index")
    public String viewIndex(HttpServletRequest request, HttpSession session){

     //  Object user = session.getAttribute("loginUsers");
//        System.out.println("user" + user);
        Object userRole=session.getAttribute("userRole");
        String role=userRole.toString();
        System.out.println("role" + role);

        Object userName=session.getAttribute("userName");
        String name=userName.toString();
        System.out.println("name" + name);

        request.setAttribute("trees",treeService.getAllTree(role));
        return "index";
    }
}
